<?php
require '../../include/library.inc.php';
require '../../include/admin_login.inc.php';
require '../../include/paging.inc.php';

head_admin("Новини");
$lang = 1;

		  

	
	$sql = "SELECT
			c.new_id,
			c.creation_time,
			c.published,
			
			d.title
			
		FROM
			news AS c,
			news_description AS d
		WHERE
		
			c.new_id = d.new_id
			
			AND
			
			d.lang_id = '".$lang."'
			
		  ";
	



if (!isset($_GET['sort'])) $_GET['sort'] = 1;
if (!isset($_GET['sortBy'])) $_GET['sortBy'] = 2;

$paging = new Paging($sql, $_GET['sortBy'], $_GET['sort'], array(2=>"Подредба"), 30);
$result = $paging->query();
	
	
?>
		
			<?php if ($_SESSION['message']) { ?>
			<div class="message green">
				<?=$_SESSION['message']?>
			</div>
			<?php unset($_SESSION['message']); } ?>
		
		
            <div class="topbuttons">
            	<a href="new_new.php">Добави новина</a>
				
            </div>
            <h3>Новини (<?=$paging->count()?>)</h3>
            
            <table id="listing" width="100%" cellpadding="0" cellspacing="0">
			<thead>
				<tr>
					
                    <td>Заглавие</td>
                    
					<td>Публикувана</td>
                    <td>Дата</td>
					<td>Действия</td>
				</tr>
			</thead>
            
			<tbody>
            
			<?php
			  
			  
			  $i=1;
			  
			  while ($row = mysql_fetch_object($result)) {
				    
			?>
			  <tr class="<?=(($i%2)?"none":"zebra")?>">
                    
						<td>
			      <a href="new_edit.php?new_id=<?=$row->new_id?>"  title="Редактирай"><?=sth($row->title)?></a></td>
						
						<td class="switch">
							<?php if ($row->published) { ?>
							 <a href="new_publish.php?new_id=<?=$row->new_id?>&publish=0" class="turn_on" name="turn_on" title="Спри"></a>
							<?php } else { ?> 
							 <a href="new_publish.php?new_id=<?=$row->new_id?>&publish=1" class="turn_off" name="turn_off" title="Публикувай"></a>
							<?php } ?>	
						</td>
						
						<td class="sort">
							<?=date('d M Y', strtotime($row->creation_time))?>	
						</td>
						
						<td class="icons">
							
							
							<a href="new_edit.php?new_id=<?=$row->new_id?>" class="edit" title="Редактирай">Редактирай</a> 
							<a onClick="if (window.confirm('Сигурен ли си, че искаш да изтриеш <?=sth($row->title)?>?')) { document.location='new_del.php?new_id=<?=$row->new_id?>'; return false; }" class="delete" title="Изтрий">Изтрий</a>
						</td>
						
					</tr>
         <?php
              $i++;    
            } 
         ?>				  
			</tbody>
		</table>
        
        <div class="pagingwrap"><div class="paging">
			<?=$paging->display()?>
		</div></div>
        
        
            
<?php

	foot_admin(); 
?>